import axios from "../plugin/http";

export default {
  getRoles(payload, cb, errorCb) {
    axios
      .get(`/api/role/${payload.sysId}/`)
      .then(result => {
        cb(result.data);
      })
      .catch(err => {
        errorCb(err);
      });
  },
  updateRole(payload, cb, errorCb) {
    // debugger;
    axios
      .put(`/api/role/${payload.sysId}/${payload.roleId}`, {
        "header": {
          "sysCode": "IDS",
          "platform": window.navigator.platform,
          "timestamp": new Date().getTime()
        },
        "payload": {
          "roleName": payload.roleName
        }
      })
      .then(result => {
        cb(result.data);
      })
      .catch(err => {
        errorCb(err);
      });
  },
  insertRole(payload, cb, errorCb) {
    axios
      .post(`/api/role/${payload.sysId}/`, {
        "header": {
          "sysCode": "IDS",
          "platform": window.navigator.platform,
          "timestamp": new Date().getTime()
        },
        "payload": {
          "roleCode": payload.roleCode,
          "roleName": payload.roleName
        }
      })
      .then(result => {
        cb(result.data);
      })
      .catch(err => {
        errorCb(err);
      });
  },
  deleteRole(payload, cb, errorCb) {
    axios
      .delete(`/api/role/${payload.sysId}/${payload.roleId}`, {
        "header": {
          "sysCode": "IDS",
          "platform": window.navigator.platform,
          "timestamp": new Date().getTime()
        },
      })
      .then(result => {
        cb(result.data);
      })
      .catch(err => {
        errorCb(err);
      });
  }
}
